layui.use(['element', 'table', 'form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;

    getTable();

    function getTable() {
        $.ajax({
            url: "/courseTable/getRecord",
            type: "post",
            dataType: "json",
            success: function (data) {
                tablereload(data.data);
            }
        })
    }

    function tablereload(data) {
        table.render({
            elem: '#table',
            data: data,
            title: '数据列表',
            limit: 10,
            toolbar: '#toptool',
            page: {
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: "首页",
                last: "尾页",
            },
            size: 'lg',
            cols: [[//定义列
                {type: 'checkbox'},//复选框靠左
                {field: 'createDate', title: '审核时间', align: 'center'},
                {field: "userName", title: "审核人员", align: 'center'},
                {
                    field: '', title: "审核结果", align: 'center',
                    templet: function (data) {
                        if (data.type == 1) {
                            var radio = '<p>未通过</p>'
                        } else if (data.type == 2) {
                            var radio = '<p>已通过</p>'
                        } else {
                            var radio = '<p>未知</p>'
                        }
                        return radio;
                    }
                },
                {field: 'remark', title: "备注", align: 'center',templet:function (data) {
                    if (data.remark == null){
                        return "无内容";
                    }
                    return data.remark;
                    }}
                , {
                    field: '', title: "审核日志类型", align: 'center',
                    templet: function (data) {
                        if (data.aduitLogType == 1) {
                            var radio = '<p>商品</p>'
                        } else if (data.aduitLogType == 2) {
                            var radio = '<p>视频</p>'
                        } else if (data.aduitLogType == 3) {
                            var radio = '<p>微圈</p>'
                        } else if (data.aduitLogType == 4) {
                            var radio = '<p>用户</p>'
                        } else {
                            var radio = '<p>未知</p>'
                        }
                        return radio;
                    }
                }
            ]],
        });
        //搜索
        search = function search() {
            var productName = $('input[name=productName]').val();

            var classification = document.getElementById("operationType");
            var indexClass = classification.selectedIndex;
            var classId = classification.options[indexClass].value;

            var updateDate = $('input[name=updateDate]').val();
            getTable2();

            function getTable2() {
                $.ajax({
                    url: "/courseTable/getRecord",
                    type: "post",
                    dataType: "json",
                    data: {
                        'aduitLogType': classId,
                        'userName': productName,
                        "createDate": updateDate
                    },
                    success: function (data) {
                        tablereload(data.data);
                    }
                })
            }
        }
    }
});

//刷新
function Refresh() {
    location.reload();
}

//跳转
function goBack() {
    window.location.href = '/course/course-list.html';
}
